package servlets;

import bean.Bill;
import bean.Book;
import bean.User;
import dao.BillDao;
import dao.Bookdao;
import dao.Userdao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;


@WebServlet("/TEST")
public class TEST extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public TEST() {
        super();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        Bookdao bookdao = new Bookdao();
        Book book  =  bookdao.getBook("9787508344980");
        PrintWriter out = response.getWriter();
        out.println(book.getName());
        out.println(book.getIsbn());
        out.println(book.getAuthor());
        Userdao userdao = new Userdao();

        User user = userdao.getUser("smx");
        out.println(user.getEmail());
        out.println(user.getUser_name());
        out.println(user.getUser_password());

        ArrayList arrayList = bookdao.getBooks("计算机");
        for (Object it: arrayList) {
            Book tmp = (Book) it;
            out.println(tmp.getAuthor()  );
        }

        dao.BillDao billDao = new BillDao();
        ArrayList list = billDao.getAllBills();
        for (Object it: list
             ) {
            Bill bill = (Bill) it;
            out.println(bill.getAddr());
            out.println(bill.getDate());

        }
    }
}